(function() {
    var counter = 0;
    var interval = 2000;

    function slide() {
        var slides = document.getElementById("slides").getElementsByClassName("slide-item");
        var dots = document.getElementById("dots").getElementsByClassName("dot");
        var len = Math.min(slides.length, dots.length);

        counter %= len;
        for (var i = 0; i < slides.length; i++) {
            if (i === counter) {
                slides[i].classList.add("active");
                dots[i].classList.add("active");
            } else {
                slides[i].classList.remove("active");
                dots[i].classList.remove("active");
            }
        }
        counter++;
        setTimeout(slide, interval);
    }

    slide();
})();
